﻿/********************************************************************************
     File:																
            Default.aspx.cs                         
     Description:
            wColConfig列表
     Author:									
            DDBuildTools
            http://FrameWork.supesoft.com
     Finish DateTime:
            2011-12-17 16:49:18
     History:
*********************************************************************************/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

using FrameWork.web.Module.FrameWork.UserManager;
using FrameWork;
using FrameWork.Components;
using FrameWorkWeb;
using FrameWork.web.Middle.OperateCS;

namespace FrameWork.web.Module.ColConfig
{
    public partial class Default : System.Web.UI.Page
    {


        public string U_GroupID_ID = "";
        public string U_GroupID_Txt_ID = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BindData();
            }
        }

        /// <summary>
        /// 绑定数据
        /// </summary>
        private void BindData()
        {
            AllSeach all = new AllSeach();// when '1' then '是' when '0' then '否' end 
            DataSet ds = all.SupesoftPage("wColConfig", "ID,ConfigName,IsDefault,Remark", 10, AspNetPager1.CurrentPageIndex, " where 1=1", "ID", "1", false);
            DataTable dt = new DataTable();
            DataColumn dc1 = new DataColumn("ID"); dt.Columns.Add(dc1);
            DataColumn dc2 = new DataColumn("ConfigName"); dt.Columns.Add(dc2);
            DataColumn dc3 = new DataColumn("IsDefault"); dt.Columns.Add(dc3);
            DataColumn dc4 = new DataColumn("Remark"); dt.Columns.Add(dc4);
            if (ds.Tables.Count > 0)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    DataRow newdr = dt.NewRow();
                    newdr["ID"] = dr["ID"];
                    newdr["ConfigName"] = dr["ConfigName"];
                    newdr["Remark"] = dr["Remark"];
                    if (dr["IsDefault"].ToString() == "1")
                    { newdr["IsDefault"] = "是"; }
                    else { newdr["IsDefault"] = "否"; }
                    dt.Rows.Add(newdr);
                }
                GridView1.DataSource = dt;
                GridView1.DataBind();
                this.AspNetPager1.RecordCount = int.Parse(ds.Tables[1].Rows[0][1].ToString());
            }
            else
            {
                GridView1.DataSource = dt;
                GridView1.DataBind();
                GridView1.Rows[0].Cells.Clear();
                GridView1.Rows[0].Cells.Add(new TableCell());
                GridView1.Rows[0].Cells[0].ColumnSpan = GridView1.Columns.Count;
                GridView1.Rows[0].Cells[0].Text = "未搜索到记录";
                GridView1.Rows[0].Cells[0].Style.Add("text-align", "center");
                this.AspNetPager1.RecordCount = 0;
            }

        }

        /// <summary>
        /// 点击分页事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindData();
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowIndex > -1)
            {
                ((LinkButton)e.Row.FindControl("btndel")).Attributes.Add("onclick", "return confirm('确定要删除吗');");
            }
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "del")
            {
                Control c = ((Control)e.CommandSource);
                GridViewRow gvr = (GridViewRow)c.Parent.Parent;
                int index = gvr.RowIndex;
                string s = ((Label)GridView1.Rows[index].FindControl("labItemID")).Text;
                enColConfig ec = new enColConfig();
                ec.ID = int.Parse(s);
                ColConfigCS cc = new ColConfigCS();
                if (cc.ColConfig_Delete(ec) > 0)
                {
                    ColConfigItemCS cccs = new ColConfigItemCS();
                    cccs.ColConfigItem_Delete(ec.ID);
                    BindData();
                }
            }
            else if (e.CommandName == "edit")
            {
                Control c = ((Control)e.CommandSource);
                GridViewRow gvr = (GridViewRow)c.Parent.Parent;
                int index = gvr.RowIndex;
                string s = ((Label)GridView1.Rows[index].FindControl("labItemID")).Text;
                Response.Redirect("ColConfigItem.aspx?ID=" + s);
            }
        }

       
       
        
    }
}
